﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using TGIApp.Model;

namespace TGIApp.Web.Controllers
{
    public class EventVenueController : Controller
    {
        //
        // GET: /EventVenue/

        public ActionResult Index()
        {
            var proxy = new Proxy.ServiceProxy();
            var eventVenues= proxy.GetAllEventVenues();
            return View(eventVenues);
        }

        //
        // GET: /EventVenue/Details/5

        public ActionResult Details(int id)
        {
            var proxy = new Proxy.ServiceProxy();
            var eventVenue = proxy.GetEventVenueById(id);
            return View(eventVenue);
        }

        //
        // GET: /EventVenue/Create

        public ActionResult Create()
        {
            ITgiService proxy = new Proxy.ServiceProxy();
            ViewBag.Events = proxy.GetAllEvents();
            ViewBag.Venues = proxy.GetAllVenues();
            ViewBag.Templates = proxy.GetAllTicketTemplates();
            return View();
        } 

        //
        // POST: /EventVenue/Create

        [HttpPost]
        public ActionResult Create(EventVenue eventVenue)
        {
            if (ModelState.IsValid)
            {
                ITgiService proxy = new Proxy.ServiceProxy();
                proxy.CreateEventVenue(eventVenue);
            }
            return RedirectToAction("Index");
        }
        
        //
        // GET: /EventVenue/Edit/5
 
        public ActionResult Edit(int id)
        {
            ITgiService proxy = new Proxy.ServiceProxy();
            var eventVenue = proxy.GetEventVenueById(id);
            ViewBag.Events = proxy.GetAllEvents();
            ViewBag.Venues = proxy.GetAllVenues();
            ViewBag.Templates = proxy.GetAllTicketTemplates();
            return View(eventVenue);
        }

        //
        // POST: /EventVenue/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, EventVenue eventVenue)
        {
            if (ModelState.IsValid)
            {
                ITgiService proxy = new Proxy.ServiceProxy();
                proxy.UpdateEventVenue(eventVenue);
            }
            return RedirectToAction("Index");
        }

        //
        // GET: /EventVenue/Delete/5
 
        public ActionResult Delete(int id)
        {
            ITgiService proxy = new Proxy.ServiceProxy();
            var eventVenue = proxy.GetEventVenueById(id);
            return View(eventVenue);
        }

        //
        // POST: /EventVenue/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            ITgiService proxy = new Proxy.ServiceProxy();
            proxy.DeleteEventVenueById(id);
            return RedirectToAction("Index");
        }
    }
}
